#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct node{
    long long num, cnt;
};

int main() {
    int n, c, id = 0;
    long long ans = 0;
    cin >> n >> c;
    vector<int> a(n);
    vector<node> b;
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    b.push_back({a[0], 1});
    for(int i=1; i<n; i++) { // id结束是最后一个数的编号
        if(a[i] != a[i-1]) {
            b.push_back({a[i], 1});
        } else  b[b.size()-1].cnt++;
    }
    for(int i=0; i<b.size(); i++) {
        int l = i + 1, r = b.size() - 1;
        while(l<r) {
            int mid = (l + r) / 2;
            if(b[mid].num - b[i].num < c) l = mid + 1;
            else r = mid;
        }
        if(b[r].num - b[i].num == c) {
            ans += b[i].cnt * b[r].cnt;
        }
    }
    cout << ans << endl;
    return 0;
}